package cn.wit.summit.chwan.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

import cn.wit.summit.chwan.utils.LogUtils;
import it.sephiroth.android.library.widget.HListView;

public class MyHlistview extends HListView {
    public MyHlistview(Context context) {
        super(context);
    }

    public MyHlistview(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyHlistview(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }


    float startx = 0, starty = 0, endx = 0, endy = 0;
    public boolean hastoch=false;
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        Log.e("xxx","hlist "+ev.getAction());
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            getParent().requestDisallowInterceptTouchEvent(true);
            startx = ev.getX();
            starty = ev.getY();
            hastoch=true;
            Log.e("xxx","hlist 触摸");
        }else if (ev.getAction() == MotionEvent.ACTION_UP||ev.getAction()==MotionEvent.ACTION_CANCEL){
            Log.e("xxx","hlist 去掉触摸");
            hastoch=false;

        }

        if (ev.getAction() == MotionEvent.ACTION_MOVE) {
            if (Math.abs(startx - ev.getX()) > Math.abs(starty - ev.getY())) {
                Log.e("xxx","hlist横向 true");
                onTouchEvent(ev);
//                getParent().requestDisallowInterceptTouchEvent(true);
                return true;
            }else {
                getParent().requestDisallowInterceptTouchEvent(false);
                return false;
            }
        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_MOVE) {
            if (Math.abs(startx - ev.getX()) > Math.abs(starty - ev.getY())) {
                Log.e("xxx","hlist横向 消费掉事件");
//                getParent().requestDisallowInterceptTouchEvent(true);
            }
        }
        return super.onTouchEvent(ev);
    }
}
